package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"

	cent "gitee.com/shuokeyun/common/ent"
)

type Order struct {
	ent.Schema
}

func (Order) Mixin() []ent.Mixin {
	return []ent.Mixin{
		cent.OrmMixin{},
	}
}

func (Order) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entsql.Annotation{
			Table: "sk_order",
		},
	}
}

func (Order) Fields() []ent.Field {
	return []ent.Field{
		field.String("order_sn").Immutable().Unique().Comment("订单号"),
		field.Int32("app_id").Immutable().Comment("来源"),
		field.Int8("status").Default(-1).Comment("状态 -1等待付款;1审核通过;2等待审核;3审核失败;4商户取消"),
		field.Int8("settle_type").Immutable().Comment("结算方式 1订单;2日结;3月结"),
		field.Int32("price_area").Immutable().Comment("物价区域"),
		field.Int32("brand").Immutable().Comment("品牌id"),
		field.Int32("total_price").Immutable().Comment("实际需支付金额(分)"),
		field.Int32("order_price").Immutable().Comment("订单金额(分)"),
		field.Int32("merchant_id").Immutable().Comment("商户id"),
		field.Int32("merchant_user_id").Immutable().Comment("商户用户id"),
		field.Int8("pay_status").Default(-1).Comment("1已支付;-1未支付"),
		field.Int8("pay_method").Comment("付款方式 1微信;2支付宝;3钱包"),
		field.Time("pay_time").Optional().Nillable().Comment("支付时间"),
		field.Int32("refund_price").Optional().Comment("退款金额(分)"),
		field.Int8("refund_status").Optional().Default(-1).Comment("退款状态 -1无退款;1全部退款;2部分退款"),
		field.Time("refund_time").Optional().Nillable().Comment("最后一次退款时间"),
		field.Int8("report_status").Optional().Default(-1).Comment("报告状态 -1未出;1全部已出;2部分已出"),
		field.Time("report_time").Optional().Nillable().Comment("最后一次出报告时间"),
		field.Int32("salesman_id").Comment("业务员"),
	}
}

func (Order) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("barcodes", OrderBarcode.Type),
		edge.To("ext", OrderExt.Type).Unique(),
		edge.To("originals", OrderOriginal.Type),
		edge.To("users", OrderUser.Type),
	}
}
